<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
    <c:set var="ctx" value="${pageContext.request.contextPath}" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>厂商详情</title>
    <jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
    <div class="Wrapper">
                <form id="formSet1" class="l-form">
                    <div class="fieldset1 tabel_col clearFix">
                        <div class="caption">
                            <span class="title">${template.name}</span>
                        </div>
                        <div class="fieldBox col_33">
                            <div class="label">支付表号</div>
                            <div class="field">
                                <span name="mfrNm" id="mfrNm">${template.paySchNo}</span>
                            </div>
                        </div>
                        <div class="fieldBox col_33">
                            <div class="label">状态</div>
                            <div class="field">
                                <span name="isSpl" id="isSpl">
                                    <c:if test="${template.status=='0'}">
                                        未作答
                                    </c:if>
                                    <c:if test="${template.status=='1'}">
                                        已保存
                                    </c:if>
                                    <c:if test="${template.status=='2'}">
                                        已作答
                                    </c:if>
                                </span>
                            </div>
                        </div>
                        <div class="fieldBox col_33">
                            <div class="label">产品名称</div>
                            <div class="field">
                                <span name="mfrFax" id="mfrFax">${template.prjNm}</span>
                            </div>
                        </div>
                        <div class="fieldBox col_33">
                            <div class="label">逾期天数</div>
                            <div class="field">
                                <span name="mfrAddr" id="mfrAddr">${template.ovdDay}</span>
                            </div>
                        </div>
                        <div class="fieldBox col_33">
                            <div class="label">逾期金额</div>
                            <div class="field">
                                <span name="mfrTel" id="mfrTel">${template.ovdAmount}</span>
                            </div>
                        </div>
                        <div class="fieldBox col_33">
                            <div class="label">罚息</div>
                            <div class="field">
                                <span name="lmNm" id="lmNm">${template.penaltyAmount}</span>
                            </div>
                        </div>
                        <div class="fieldBox col_33">
                            <div class="label">问卷人员</div>
                            <div class="field">
                                <span name="lmIdNum" id="lmIdNum">${template.personNm}</span>
                            </div>
                        </div>
                        <div class="fieldBox col_33">
                            <div class="label">问卷时间</div>
                            <div class="field">
                                <span name="lmOfficeTel" id="lmOfficeTel">${template.date}</span>
                            </div>
                        </div>
                        <div class="fieldBox col_33">
                            <div class="label">问卷结果</div>
                            <div class="field">
                                <span name="lmAddr" id="lmAddr">${template.result}</span>
                            </div>
                        </div>
                    </div>



                    <jsp:include page="/WEB-INF/views/dk/template/add.jsp" >
                        <jsp:param name="templateCd" value="${template.templateCd}" />
                    </jsp:include>
                    <div class="btnsBox">
                        <span class="sq-button sq-button-round" onclick="save(1);">暂存</span>
                        <span class="sq-button sq-button-round" onclick="save(2);">提交问卷</span>
                    </div>
                </form>
        </div>
    </div>
</div>


<script type="text/javascript">
    /**
     * 保存
     * @param status 问卷状态
     */
    function save(status){
    var formSet1 = $("#formSet1")
    var data = JSON.stringify(formSet1.serializeArray());
    var ruleFlag = "${template.ruleFlag}";
    var templateId = "${template.id}";
    var templateName = "${template.name}";
    var qtnType = "${template.qtnType}";
    var id = "${id}";
        var deleteSelection = []
        $("input[disabled='disabled']").each(function(index,item){
            var s = {}
            s.name = $(item).attr("name");
            s.value = $(item).val();
            deleteSelection.push(s);
        })
    $.ajax({
        type:"post",
        dataType:"json",
        data:{templateId:templateId,templateName:templateName,selection:data,pkId:id,tableName:"DK_QUESTNE_LOG",qtnType:qtnType,status:status,deleteSelection:JSON.stringify(deleteSelection)},
        url:"<%=path%>/template/save.do",
        success:function(data){
            // 更新问卷状态  问卷结果
            if(data.score==0 && status==2){// 暂存不计算分数，就不提示了
                alert("问卷分数计算失败");
                return false;
            }
            updateQ(id,status,data.score,data.isMatch);
            // 刷新父页面
            var TAB=top.mainApp.parentTab;
            var currentTabid=TAB.getSelectedTabItemID();
            var currFrameElement=top.$("#"+currentTabid).get(0);
            var callback=currFrameElement.W2W.callback;
            callback();
            if(status==2){//关闭页面
                TAB.removeSelectedTabItem();
            }else{
                TAB.overrideSelectedTabItem({
                    tabid: 'dk_qtn_modify'+ruleFlag,
                    text: '答卷',
                    url: '/dk/dkquestnelog/toUpdatePage.do?ruleFlag='+ruleFlag
                });
            }

        },
        error:function(){
            alert("保存失败");
        }
    });
}

    /**
     *
     * @param id 业务主键
     * @param status 问卷状态
     * @param res 问卷结果
     */
    function updateQ(id,status,res,isMatch){
        $.ajax({
            type:"post",
            dataType:"text",
            data:{id:id,status:status,result:res,isMatch:isMatch},
            url:"<%=path%>/dk/dkquestnelog/update.do",
            success:function(data){
               alert("保存成功");
            }
        });
    }
</script>



</body>
</html>
